<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <!-- 数据来源为父组件 -->

    <!-- 父组件向子组件传递数据   (只读的状态, 子组件不能进行修改)-->
    <!-- 1. 在子组件的标签上自定义属性, =后面写传递的数据 -->
    <!-- 2. 在子组件内部props进行接收 -->

    <div id="app">
        <my-father></my-father>
    </div>

    <!-- 父组件 -->
    <template id="father">
        <div>
            <h2>
                我是父组件  --- {{ num }}
            </h2>
            <button @click="add">+++1</button>
            <my-son :count="num"></my-son>
        </div>
    </template>

    <!-- 子组件 -->
    <template id="son">
        <div>
            <h4>
                我是子组件  ---  {{ count }}
            </h4>
            <button @click="add">修改</button>
        </div>
    </template>

    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>

        let Son = {
            template: "#son",
            // 用来接收父组件传递过来的内容 接收过来的数据会添加到this上
            props: ["count"],
            methods: {
                add() {
                    this.count += 1
                }
            }
        }



        let Father = {
            template: "#father",
            data() {
                return {
                    num: 100
                }
            },
            components: {
                "my-son": Son
            },
            methods: {
                add() {
                    this.num += 1
                }
            }
        }

        new Vue({
            // 元素
            el: "#app",
            components: {
                "my-father": Father
            }
        })
    </script>
</body>

</html>